/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* **********************************************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Theme_Builder.Utility
{
    // This class will handle the checks we need for pre-req's to installing and using
    //  this application.  The current list of checks that we require are:
    //  1. .Net 3.0 Installed
    //  2. Office 2007's primary interop assemblies present
    //
    // TODO: handle hooking these checks up correctly

    [RunInstaller(true)]
    public partial class ThemeBuilderInstaller : Installer
    {
        public ThemeBuilderInstaller()
        {
            InitializeComponent();

            // Attach ourselves to the before install event
            this.BeforeInstall += new InstallEventHandler(ThemeBuilderInstaller_BeforeInstall);
        }

        void ThemeBuilderInstaller_BeforeInstall(object sender, InstallEventArgs e)
        {
            bool installed = false;

            System.OperatingSystem osInfo = System.Environment.OSVersion;

            // If we're vista, everything should be good to go
            if (osInfo.Version.Major >= 6)
            {
                return;
            }
            else
            {
                // Less than Vista, check for .Net 3.0 being present
                string netThree = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup";
                object resultNet = Registry.GetValue(netThree, "InstallSuccess", null);

                if ((resultNet != null) && ((int)resultNet == 1))
                {
                    installed = true;
                }

                if (!installed)
                {
                    MessageBox.Show("The .Net Framework 3.0 is required before installing this application.\r\n\r\nTo install the .Net Framework 3.0, please visit:\r\nhttp://go.microsoft.com/fwlink/?linkid=69404\r\n\r\n",
                        ".Net Framework 3.0 Required",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);

                    // Lauch a browser pointing to where they can download the .Net Framework 3.0
                    System.Diagnostics.Process.Start(@"http://go.microsoft.com/fwlink/?linkid=69404");

                    throw (new InstallException(".Net Framework 3.0 is not installed"));
                }

                installed = false;                          // reset installed state

                // Check for the presence of the PIA's
                // TODO: hook up the check for PIA's
                // I don't think that these are needed on Vista with Office installed.
            }
        }
    }
}